﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: 录入限制管理
//最后修改: 2010-10-11
//最后修改: 2010-10-19 李晓忠 从缓存中获取实体
using System;
using System.Collections.Generic;
using System.Text;


using TRPOP.CMS.Model;
using TRPOP.CMS.DALFactory;
using TRPOP.Common;
using TRPOP.CMS.Plugin;

namespace TRPOP.CMS.Business
{
    public class FormInputLimitTypeManage
    {

        private IFormInputLimitTypeDAL Idal;
        public FormInputLimitTypeManage()
        {
            Idal = DataAccess.CreateFormInputLimitTypeDAL();
        }

        #region 保存 Save
        ///	<summary>
        ///	保存
        ///	</summary>
        ///	<param name="FormInputLimitTypeInfo"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult Save(FormInputLimitTypeInfo info)
        {
            return Idal.Save(info);
        }

        #endregion

        #region 获取实体 GetInfoById
        ///	<summary>
        ///	获取实体
        ///	</summary>
        ///	<param name="formInputLimitTypeId"></param>
        ///	<returns>FormInputLimitTypeInfo</returns>
        public FormInputLimitTypeInfo GetInfoById(int id)
        {
            return Idal.GetInfoById(id);
        }
        #endregion

        #region 删除 DeleteInfoById
        ///	<summary>
        ///	删除
        ///	</summary>
        ///	<param name="id"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult DeleteInfoById(int id)
        {
            return Idal.DeleteInfoByIds(id.ToString());
        }
        #endregion

        #region 删除 DeleteInfoByIds
        ///	<summary>
        ///	删除
        ///	</summary>
        ///	<param name="ids"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult DeleteInfoByIds(string ids)
        {
            return Idal.DeleteInfoByIds(ids);
        }
        #endregion

        #region 自定义列表（无分页） GetListByCondition
        ///	<summary>
        ///	自定义列表（无分页）
        ///	</summary>
        ///	<param name="topn">前N条，为0时表示所有符合条件的</param>
        ///	<param name="condition">自定义条件，要以And开头</param>
        ///	<param name="orderby">排序，不需要Order by </param>
        ///	<returns>List<FormInputLimitTypeInfo></returns>
        public List<FormInputLimitTypeInfo> GetListByCondition(int topn, string condition, string orderby)
        {
            return Idal.GetListByCondition(topn, condition, orderby);
        }
        #endregion

        #region 自定义列表（分页） GetListByPager
        ///	<summary>
        ///	自定义列表（分页）
        ///	</summary>
        ///	<returns>List<FormInputLimitTypeInfo></returns>
        public List<FormInputLimitTypeInfo> GetListByPager(int pageNumber, int pageSize, string condition, string orderby, out int recordCount)
        {
            return Idal.GetListByPager(pageNumber, pageSize, condition, orderby, out  recordCount);
        }
        #endregion

        #region  从缓存中获取实体 GetInfoByIdFromCache
        /// <summary>
        /// 从缓存中获取实体 暂时没有删除缓存的触发函数，需要通过前台来手动删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FormInputLimitTypeInfo GetInfoByIdFromCache(int id)
        {
            //ICache mICache = ICacheAccess.GetInstance();
            //string strCacheKey = string.Format(CacheKeys.FormInputLimitType_GetInfoByIdFromCache, id);
            //if (mICache.IsExist(strCacheKey) == false)
            //{
            //    List<FormInputLimitTypeInfo> m_FormInputLimitTypeInfoList = null;
            //    m_FormInputLimitTypeInfoList = Idal.GetListByCondition(0, "", "");
            //    FormInputLimitTypeInfo m_FormInputLimitTypeInfo = m_FormInputLimitTypeInfoList.Find(delegate(FormInputLimitTypeInfo info) { return info.FormInputLimitTypeId == id; });
            //    if (m_FormInputLimitTypeInfo == null)
            //    {
            //        m_FormInputLimitTypeInfoList = Idal.GetListByCondition(0, "", "");
            //    }
            //    m_FormInputLimitTypeInfo = m_FormInputLimitTypeInfoList.Find(delegate(FormInputLimitTypeInfo info) { return info.FormInputLimitTypeId == id; });
            //    mICache.Save(strCacheKey, m_FormInputLimitTypeInfo, CacheKeys.FormInputLimitTypeTimeSecond);
            //    return m_FormInputLimitTypeInfo;
            //}
            //return (FormInputLimitTypeInfo)mICache.Read(strCacheKey);

            return CacheHelper.GetByICache<FormInputLimitTypeInfo>(
                    string.Format(CacheKeys.FormInputLimitType_GetInfoByIdFromCache, id),
                    CacheKeys.FormInputLimitTypeTimeSecond,
                    ICacheAccess.GetInstance(),
                    () =>
                    {
                        List<FormInputLimitTypeInfo> m_FormInputLimitTypeInfoList = new List<FormInputLimitTypeInfo>();
                        m_FormInputLimitTypeInfoList = Idal.GetListByCondition(0, "", "");
                        FormInputLimitTypeInfo m_FormInputLimitTypeInfo = m_FormInputLimitTypeInfoList.Find(delegate(FormInputLimitTypeInfo info) { return info.FormInputLimitTypeId == id; });
                        if (m_FormInputLimitTypeInfo == null)
                        {
                            m_FormInputLimitTypeInfoList = Idal.GetListByCondition(0, "", "");
                        }
                        return m_FormInputLimitTypeInfoList.Find(delegate(FormInputLimitTypeInfo info) { return info.FormInputLimitTypeId == id; });
                    }
                );

        }
        #endregion


    }
}
